package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.TChoice;
import com.ruoyi.project.system.service.ITChoiceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 多选选项Controller
 * 
 * @author ruoyi
 * @date 2020-05-14
 */
@RestController
@RequestMapping("/system/choice")
public class TChoiceController extends BaseController
{
    @Autowired
    private ITChoiceService tChoiceService;

    /**
     * 查询多选选项列表
     */
    @PreAuthorize("@ss.hasPermi('system:choice:list')")
    @GetMapping("/list")
    public TableDataInfo list(TChoice tChoice)
    {
        startPage();
        List<TChoice> list = tChoiceService.selectTChoiceList(tChoice);
        return getDataTable(list);
    }

    /**
     * 导出多选选项列表
     */
    @PreAuthorize("@ss.hasPermi('system:choice:export')")
    @Log(title = "多选选项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TChoice tChoice)
    {
        List<TChoice> list = tChoiceService.selectTChoiceList(tChoice);
        ExcelUtil<TChoice> util = new ExcelUtil<TChoice>(TChoice.class);
        return util.exportExcel(list, "choice");
    }

    /**
     * 获取多选选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:choice:query')")
    @GetMapping(value = "/{choiceId}")
    public AjaxResult getInfo(@PathVariable("choiceId") Integer choiceId)
    {
        return AjaxResult.success(tChoiceService.selectTChoiceById(choiceId));
    }

    /**
     * 新增多选选项
     */
    @PreAuthorize("@ss.hasPermi('system:choice:add')")
    @Log(title = "多选选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TChoice tChoice)
    {
        return toAjax(tChoiceService.insertTChoice(tChoice));
    }

    /**
     * 修改多选选项
     */
    @PreAuthorize("@ss.hasPermi('system:choice:edit')")
    @Log(title = "多选选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TChoice tChoice)
    {
        return toAjax(tChoiceService.updateTChoice(tChoice));
    }

    /**
     * 删除多选选项
     */
    @PreAuthorize("@ss.hasPermi('system:choice:remove')")
    @Log(title = "多选选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{choiceIds}")
    public AjaxResult remove(@PathVariable Integer[] choiceIds)
    {
        return toAjax(tChoiceService.deleteTChoiceByIds(choiceIds));
    }
}
